<?php 
/**
 * 接口Controller基类
 * @package Core
 * @author 江羿平<jyp@cjkt.com>
 */
namespace Core;
use CI_Controller;
class Controller extends CI_Controller{

	public function __construct()
	{
		parent::__construct();
		$this->lang->load('admin_common', $this->session->admin_language);
	}
	
	//检测后台是否登录
	public function check_admin_login(){
		if(!$this->session->has_userdata('admin_login') || $this->session->admin_login != 1){
			redirect('/admin/auth/login');
			exit;
		}
	}

	/**
	 * 响应
	 * 生成一个响应
	 * @param mixed 数据
	 * @param int 状态码
	 * @param array 请求头
	 */
	public function response($data = null, $status = 200, array $headers = array(), $json = false)
	{
		if (is_array($data) OR $json) {
			$this->output->set_content_type('application/json');
			$this->output->set_output(json_encode($data));
		} else {
			$this->output->set_output($data);
		}

		$this->output->set_status_header($status);
		
		foreach ($headers as $key => $value) {
			if (is_integer($key)) {
				$this->output->set_header($value);
			} else {
				$this->output->set_header($key.': '.$value);
			}
		}
	}

}